package ext.tianma.cascade.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ptc.core.meta.common.TypeIdentifier;
import com.ptc.core.meta.common.impl.TypeIdentifierUtilityHelper;

import wt.enterprise.Master;
import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.fc.PersistenceServerHelper;
import wt.fc.QueryResult;
import wt.fc.ReferenceFactory;
import wt.fc.WTObject;
import wt.fc.WTReference;
import wt.iba.definition.StringDefinition;
import wt.occurrence.OccurrenceHelper;
import wt.part.PartUsesOccurrence;
import wt.part.WTPart;
import wt.part.WTPartHelper;
import wt.part.WTPartMaster;
import wt.part.WTPartUsageLink;
import wt.query.QueryException;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.util.WTException;
import wt.util.WTProperties;
import wt.util.WTPropertyVetoException;
import wt.util.WTRuntimeException;
import wt.vc.Iterated;
import wt.vc.baseline.Baseline;
import wt.vc.baseline.BaselineMember;
import wt.vc.config.ConfigHelper;
import wt.vc.config.LatestConfigSpec;

public class QueryHelper {
	/**
	 * 根据class文件 获取 class文件所在路径
	 * @param o
	 * @return
	 * @throws IOException
	 */
	public static String getClassfilePath(Class<?> o) throws IOException {
		String codebasePath = WTProperties.getLocalProperties().getProperty("wt.codebase.location");
        char c[] = o.getPackage().getName().toCharArray();
        String s = "";
        for(int i = 0; i < c.length; i++)
        {
            if(c[i] == '.')
            {
                s = (new StringBuilder(String.valueOf(s))).append("\\").toString();
            } else
            {
                s = (new StringBuilder(String.valueOf(s))).append(c[i]).toString();
            }
        }

        return (new StringBuilder(String.valueOf(codebasePath))).append("\\").append(s).append("\\").toString();
    }
	
	
	/**
	 * 根据软属性内部名称查找气显示名称
	 * @param containerName
	 * @return
	 * @throws QueryException
	 * @throws WTException
	 */
	@SuppressWarnings("deprecation")
    public static String getIBADisplayByName(String name) throws QueryException,WTException{
		name = name.trim();
		StringDefinition def = null;
		
		QuerySpec qs = new QuerySpec(StringDefinition.class);
		SearchCondition sc = new SearchCondition(StringDefinition.class, "name", "=", name);
		qs.appendWhere(sc);
		
		QueryResult qr = PersistenceHelper.manager.find(qs);
		
		while (qr.hasMoreElements()) {
			def = (StringDefinition) qr.nextElement();
		}
		
		if(def == null){
			return name;
		}
		String displayName = def.getDisplayName(); 
		if("备注".equals(displayName)){
			displayName="实际质量状态描述";
		}
		return displayName;
	}
	

}
